home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / misc / update / tpasc302.cpt / TCL Update / New ArtClass Files / CToolText.p < prev   
Encoding:
Text File  |  1990-05-11  |  3.5 KB  |  143 lines

  1. {****************************************************}
  2. {         CToolText.p}
  3. {}
  4. {        The ToolText Class}
  5. {}
  6. {        A typical text tool for typing text in a Painting. A Caption, which}
  7. {        is a subclass of CEditText, is created to handle the text. This}
  8. {        actually becomes a subpane of the painting. The Pane itself is}
  9. {        disposed after the typing is completed, but the bits within the}
  10. {        Pane become part of the painting.}
  11. {}
  12. {        SUPERCLASS = CPaintTask}
  13. {}
  14. {        Copyright ⌐ 1989, Symantec Corporation.  All rights reserved.            }
  15. {}
  16. {****************************************************}
  17.  
  18. unit CToolText;
  19.  
  20. interface
  21.  
  22.     uses
  23.         TCL, MoreTCL, ArtClassIntf;
  24.  
  25. {** Class Constants **}
  26.  
  27.     const
  28.         iTEXT = 5;            { Index for Text Task name            }
  29.  
  30. implementation
  31.  
  32.  
  33.  
  34. {*** C O N S T R U C T I O N / D E S T R U C T I O N   M E T H O D S ***}
  35.  
  36.  
  37.  
  38. {****************************************************}
  39. { IToolText}
  40. {}
  41. {        Initialize a ToolText object}
  42. {}
  43. {****************************************************}
  44.  
  45.     procedure CToolText.IToolText (aPaintPane: CPaintPane; aPainting: CBitMap);
  46.     begin
  47.         IPaintTask(iTEXT, aPaintPane, aPainting);
  48.  
  49.         itsCaption := nil;
  50.         done := FALSE;
  51.     end;
  52.  
  53.  
  54. {****************************************************}
  55. { BeginTracking (OVERRIDE)}
  56. {}
  57. {        Initial mouse down determines the location for the text}
  58. {}
  59. {****************************************************}
  60.  
  61.     procedure CToolText.BeginTracking (var startPt: Point);
  62.         var
  63.             theCaption: CCaption;           { Altered by TCL Weaver 1.0 (5/9/90) }
  64.  
  65.     begin
  66.                                         { Create a Caption Pane to handle    }
  67.                                         {   keystrokes and text display        }
  68.  
  69.         TextFont(gFontNum);                { Set font characteristics            }
  70.         TextSize(gFontSize);
  71.         TextFace(gFontStyle);
  72.                                         { Note how the PaintPane is both    }
  73.                                         {   the enclosure and supervisor        }
  74.                                         {   of the Caption. This is                }
  75.                                         {   important because we want the    }
  76.                                         {   PaintPane to become the Gopher    }
  77.                                         {   again when we get rid of the        }
  78.                                         {   Caption pane.                        }
  79.  
  80.         new(theCaption);                { Altered by TCL Weaver 1.0 (5/9/90) }
  81.         itsCaption := theCaption;
  82.         itsCaption.ICaption(itsPaintPane, itsPaintPane, PNTG_WIDTH, startPt.h, startPt.v);
  83.  
  84.         itsCaption.SetLineSpacing(gLineSpacing);
  85.  
  86.         itsCaption.Activate;
  87.         gGopher := itsCaption;
  88.         gSleepTime := 0;
  89.                                 { Make Caption the Gopher so it            }
  90.                                 {   receives key and menu commands    }
  91.  
  92.         CDirector(itsPaintPane.itsSupervisor).itsGopher := itsCaption;
  93.     end;
  94.  
  95.  
  96. {****************************************************}
  97. { DoTask (OVERRIDE)}
  98. {}
  99. {        Finish off Text}
  100. {}
  101. {****************************************************}
  102.  
  103.     procedure CToolText.DoTask;
  104.         var
  105.             tFrame: Rect;
  106.  
  107.     begin
  108.         if not done then
  109.             begin                            { We have to save stuff for Undo,    }
  110.                                         {   copy the image from the            }
  111.                                         {   Caption to the Painting, then        }
  112.                                         {   throw out the Caption.            }
  113.                 itsCaption.Deactivate;
  114.                 itsCaption.GetFrame(tFrame);
  115.                 itsCaption.FrameToEnclR(tFrame);
  116.  
  117.                 SaveForUndo(tFrame);
  118.  
  119.                 itsCaption.DrawInPort(itsPainting.macPort);
  120.                 itsCaption.Free;
  121.                 CDirector(itsPaintPane.itsSupervisor).itsGopher := itsPaintPane;
  122.                 done := TRUE;
  123.             end;
  124.     end;
  125.  
  126.  
  127. {****************************************************}
  128. { Undo (OVERRIDE)}
  129. {}
  130. {        Undo typing of text}
  131. {}
  132. {****************************************************}
  133.  
  134.     procedure CToolText.Undo;
  135.     begin
  136.         if not done then                 { We must be sure to finalize the    }
  137.             DoTask;                            {   typing before undoing it.            }
  138.  
  139.         inherited Undo;
  140.     end;
  141.  
  142.  
  143. end.